package com.bustle.user.webservice;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.jws.WebParam;
import javax.jws.WebService;

import com.bustle.user.AuthenticationDtoManager;
import com.bustle.user.AuthenticationException;
import com.bustle.user.dto.user.UserDto;

@WebService
public interface AuthenticationDtoWebService
{
  public UserDto authenticate(@WebParam(name = "login") String aLogin, @WebParam(name = "password") String aPassword) throws AuthenticationException;
  public UserDto createUser(@WebParam(name = "user") UserDto aUser, @WebParam(name = "login") String aLogin, @WebParam(name = "password") String aPassword) throws AuthenticationException;

  public UserDto getUser(@WebParam(name = "id") int anId);
  public void updateUser(@WebParam(name = "user") UserDto aUser);

  @Stateless
  @WebService(endpointInterface = "com.bustle.user.webservice.AuthenticationDtoWebService")
  public class DefaultAuthenticationDtoWebService implements AuthenticationDtoWebService
  {
    @Override
    public UserDto authenticate(String aLogin, String aPassword) throws AuthenticationException
    {
      return authenticationDtoManager.authenticate(aLogin, aPassword);
    }

    @Override
    public UserDto createUser(UserDto aUser, String aLogin, String aPassword) throws AuthenticationException
    {
      authenticationDtoManager.createUser(aUser, aLogin, aPassword);
      return aUser;
    }

    @Override
    public UserDto getUser(int anId)
    {
      return authenticationDtoManager.getUser(anId);
    }

    @Override
    public void updateUser(UserDto aUser)
    {
      authenticationDtoManager.updateUser(aUser);
    }

    @EJB
    protected AuthenticationDtoManager authenticationDtoManager;
  }
}
